package controller

import (
	"docker_go/internal/models/vo"
	"docker_go/internal/service"
	"github.com/gin-gonic/gin"
	"net/http"
)

type StudentController struct {
}

func NewStudentController() StudentController {
	return StudentController{}
}

func (s StudentController) GetAll(c *gin.Context) {
	svc := service.New(c.Request.Context())
	students := svc.GetAllStudents()
	c.JSON(http.StatusOK, gin.H{
		"students": students,
	})
}

func (s StudentController) Pong(c *gin.Context) {
	c.JSON(http.StatusOK, gin.H{"message": "pong"})
}

func (s StudentController) InsertStudent(c *gin.Context) {
	svc := service.New(c.Request.Context())
	var stu vo.Student
	err := c.Bind(&stu)
	svc.InsertStudent(stu)
	if err != nil {
		return
	}
	c.JSON(http.StatusOK, gin.H{"code": "0", "message": "ok"})
}
